﻿Imports System.Data.SqlClient
Public Class SuaDSSinhVien

    Private _str As String
    Private _maLop As Object
    Dim _code As String

    Sub New(ByVal str As String, ByVal MaLop As Object)
        ' TODO: Complete member initialization 
        _str = str
        _maLop = MaLop
    End Sub

    Private Sub btnSua_Click(sender As System.Object, e As System.EventArgs) Handles btnSua.Click
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = KetNoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        Dim sex As Integer
        If radioButton1.Checked = True Then
            sex = 0
        Else
            sex = 1
        End If
        Dim TenLop As String = cbxLop.SelectedItem.ToString()
        cmd.CommandText = "select* from Lop where TenLop ='" + TenLop + "'"
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Dim MaLop As String = td.Rows(0)(0).ToString()
        cmd.CommandText = "UPDATE SINHVIEN SET HoTen='" + txtTenSinhVien.Text + "',GioiTinh=" + sex + ",NgaySinh='" + mskNgaySinh.Text + "',DiaChi='" + txtNoiSinh.Text + "',Email='" + txtOHienTai.Text + "',MaLop='" + MaLop + "'WHERE MaSinhvien='" + txtMaSinhVien.Text + "'"
        Dim result As DialogResult
        result = MessageBox.Show("BẠN CÓ MUỐN THAY ĐỔI THÔNG TIN KHÔNG?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = DialogResult.Yes Then
            cmd.ExecuteNonQuery()
            MessageBox.Show("CẬP NHẬT THÀNH CÔNG", "THÔNG BÁO")
        End If
        con.Close()
        Me.Close()
        Dim frm As New DanhSachSinhVien(Lop_ID)
        frm.Show()

    End Sub

    Private Sub btnThoat_Click(sender As System.Object, e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub
    Private Sub btnKetQuaHocTap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim MaSV As String
        Dim TenSV As String
        MaSV = txtMaSinhVien.Text
        TenSV = txttsv.Text
        Dim frmsua As New SuaKetQua(MaSV, TenSV)
        frmsua.Show()
    End Sub

    Private Sub SuaDSSinhVien_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = KetNoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "SELECT SinhVien_ID,TenSinhVien,GioiTinh,NgaySinh,NoiSinh,NoiOHienTai,KhoaHoc,LyLich,TenLop,HinhAnh FROM SinhVien,Lop WHERE Lop_ID=ID_Lop and SinhVien_ID='" + _code + "'"
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        'MessageBox.Show(td.Rows[0][8].ToString());
        Me.txtMaSinhVien.Text = td.Rows(0)(0).ToString()
        Me.txtTenSinhVien.Text = td.Rows(0)(1).ToString()
        Me.mskNgaySinh.Text = td.Rows(0)(3).ToString()
        Me.txtNoiSinh.Text = td.Rows(0)(4).ToString()
        Me.txtOHienTai.Text = td.Rows(0)(5).ToString()
        ' this.cbxLop.Items.Add(td.Rows[0][8].ToString());
        Dim sex As Integer
        sex = Convert.ToInt16(td.Rows(0)(2))
        If sex = 0 Then
            radioButton1.Checked = True
        Else
            radioButton2.Checked = True
        End If
        con.Close()

    End Sub

    Private Function txttsv() As Object
        Throw New NotImplementedException
    End Function

    Private Function cbxLop() As Object
        Throw New NotImplementedException
    End Function

    Private Function Lop_ID() As Object
        Throw New NotImplementedException
    End Function

End Class